package main.java.com.example;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @description: java类作用描述
 * @author: cong zhi
 * @createDate: 2022/6/16 7:54
 * @updateUser: cong zhi
 * @updateDate: 2022/6/16 7:54
 * @updateRemark: 修改内容
 * @version: v1.0
 */
public class Customer {

    private String name;

    private Vector<Rental> _rentals = new Vector<Rental>();

    public Customer(String name) {
        this.name = name;
    }

    public void addRental(Rental arg) {
        _rentals.addElement(arg);
    }

    public String getName() {
        return name;
    }

    public String textStatement() {
        double totalAmount = 0;
        int frequentRenterPoints = 0;
        Enumeration<Rental> rental = _rentals.elements();
        String result = "Rental Record for " + getName();
        while (rental.hasMoreElements()) {
            double thisAmount = 0;
            Rental each = (Rental) rental.nextElement();
            thisAmount = each.getCharge();
            frequentRenterPoints++;
            if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE && each.getDaysRented() > 1) {
                frequentRenterPoints++;
            }
            result += "\n\t   " + each.getMovie().getTitle() + "\t" + thisAmount;
            totalAmount += thisAmount;
        }
        result += "\n Amount owed is " + totalAmount;
        result += "\n You earned " + frequentRenterPoints + " frequent renter points";
        return result;
    }
}
